﻿package plugin.chatflash.controller
{
    import __AS3__.vec.*;
    import cmd.*;
    import com.core.*;
    import com.sh.game.consts.*;
    import com.sh.game.global.*;
    import com.sh.game.net.*;
    import com.sh.game.util.*;
    import flash.display.*;
    import flash.events.*;
    import flash.external.*;
    import flash.geom.*;
    import flash.text.*;
    import flash.utils.*;
    import manager.*;
    import morn.core.components.*;
    import plugin.chatflash.*;
    import plugin.chatflash.component.*;
    import plugin.chatflash.model.*;
    import plugin.union.*;
    import pluginfw.*;
    import view.message.*;
    import view.uilt.*;

    public class ChannelController extends Object
    {
        private var mChatUI:GameChat;
        private const SEPARATE:String = "#!";
        private var mChannels:Vector.<ChatChannelBase>;
        private var mShowingTip:Boolean = false;
        private var mTextList:Vector.<Object>;
        private const MAX_COUNT:int = 50;
        private var faceDic:Dictionary;
        private var faceKey:int = 0;
        private var whiteSpace:Shape;
        private var isChecking:Boolean = false;

        public function ChannelController(param1:GameChat)
        {
            this.faceDic = new Dictionary();
            this.mChatUI = param1;
            this.whiteSpace = new Shape();
            this.whiteSpace.graphics.beginFill(0, 0.1);
            this.whiteSpace.graphics.drawRect(0, 0, 4, 4);
            this.whiteSpace.graphics.endFill();
            this.mChannels = new Vector.<ChatChannelBase>;
            this.mChannels.push(new ChatChannelBase(ChatCMD.ChannelAll));
            this.mChannels.push(new ChatChannelBase(ChatCMD.ChannelStage, 3));
            this.mChannels.push(new ChatChannelBase(ChatCMD.ChannelTeam, 3));
            this.mChannels.push(new ChatChannelBase(ChatCMD.ChannelUnion, 3));
            this.mChannels.push(new ChatChannelBase(ChatCMD.ChannelWorld, 60));
            this.mChannels.push(new ChatChannelBase(ChatCMD.ChannelPrivate, 3));
            this.mChannels.push(new ChatChannelBase(ChatCMD.ChannelShop, 30));
            this.mChannels.push(new ChatChannelBase(ChatCMD.ChannelSpecial, 10));
            this.mChannels.push(new ChatChannelBase(ChatCMD.ChannelSystem, 0));
            this.mTextList = new Vector.<Object>;
            return;
        }// end function

        public function sendMsg(param1:ChatVO) : void
        {
            switch(param1.Type)
            {
                case 2:
                {
                    if (UserData.getUserData("level") < 70)
                    {
                        WarningManager.show(125, [70]);
                        return;
                    }
                    break;
                }
                case 4:
                {
                    if (UserData.getUserData("level") < 40)
                    {
                        WarningManager.show(125, [40]);
                        return;
                    }
                    if (UserData.getUserData("teamid") == 0)
                    {
                        WarningManager.show(127);
                    }
                    break;
                }
                case 5:
                {
                    if (UserData.getUserData("level") < 40)
                    {
                        WarningManager.show(125, [40]);
                        return;
                    }
                    if (UserData.getUserData("unionid") == 0)
                    {
                        WarningManager.show(126);
                    }
                    break;
                }
                default:
                {
                    if (UserData.getUserData("level") < 40)
                    {
                        WarningManager.show(125, [40]);
                        return;
                    }
                    break;
                    break;
                }
            }
            var _loc_2:* = this.getChannelByID(param1.Type);
            if (_loc_2)
            {
                _loc_2.sendMsg(param1);
            }
            return;
        }// end function

        public function sendStallageMsg(param1:Object) : void
        {
            var _loc_2:* = new ChatVO();
            _loc_2.Type = ChatCMD.ChannelShop;
            var _loc_3:* = UserData.getUserData();
            _loc_2.RoleID = _loc_3.rid;
            _loc_2.RoleName = _loc_3.name;
            _loc_2.title = _loc_3.title;
            var _loc_4:String = "";
            var _loc_5:* = int(param1[6]);
            _loc_4 = "出售 <font color=\'{0}\'><u>[<a href=\'event:item,{1},{2}\'>{3}</a>]</u></font>" + " <u><a href=\'event:stallage, {4}\'><font color=\'#56b938\'> 立即购买</font></a></u>";
            _loc_2.TalkContent = StringUtil.substitute(_loc_4, MColor.getqualitycolor(param1[4].quality), param1[4].itemtype, param1[0], param1[4].name, _loc_2.RoleID);
            this.sendMsg(_loc_2);
            return;
        }// end function

        public function sendMyPosMsg(param1:Object) : void
        {
            var _loc_2:Object = null;
            var _loc_3:ChatVO = null;
            _loc_3 = new ChatVO();
            _loc_3.Type = this.mChatUI.curChatID;
            var _loc_4:* = UserData.getUserData();
            _loc_3.RoleID = _loc_4.rid;
            _loc_3.RoleName = _loc_4.name;
            _loc_3.title = _loc_4.title;
            if (this.mChatUI.curChatID == ChatCMD.ChannelPrivate && this.mChatUI.mPCComponent.selectedRole)
            {
                _loc_3.ToRoleID = this.mChatUI.mPCComponent.selectedRole.rid;
                _loc_3.ToRoleName = this.mChatUI.mPCComponent.selectedRole.name;
                _loc_2 = UserData.getUserData();
                _loc_3.sex = _loc_2.sex;
                _loc_3.rein = _loc_2.rein;
                _loc_3.level = _loc_2.level;
                _loc_3.career = _loc_2.career;
            }
            if (this.mChatUI.curChatID == ChatCMD.ChannelUnion)
            {
                _loc_2 = UserData.getUserData();
                _loc_3.sex = _loc_2.sex;
                _loc_3.career = _loc_2.career;
            }
            _loc_3.msgToAnnounce = 319 + "," + _loc_4.x + "," + _loc_4.y + "," + _loc_4.stageid;
            this.sendMsg(_loc_3);
            return;
        }// end function

        public function receiveSysMsg(param1:String) : void
        {
            var _loc_2:* = new ChatVO();
            _loc_2.Type = ChatCMD.ChannelSystem;
            _loc_2.TalkContent = param1;
            this.receiveMsg(_loc_2);
            return;
        }// end function

        public function receivePosAnnounce(param1:Array) : void
        {
            var msg:ChatVO;
            var content:String;
            var value:* = param1;
            try
            {
                msg = new ChatVO();
                msg.Type = ChatCMD.ChannelWorld;
                content = "<font color=\'#f47a17\'>{0}" + "<u><a href=\'event:pos,{1},{2},{3}\'><font color=\'#56b938\'>点击前往</font></a></u>" + " <u><a href=\'event:transfer,{1},{2},{3}\'><font color=\'#56b938\'>传送</font></a></u>";
                msg.TalkContent = StringUtil.substitute(content, value[0], value[1], value[2], value[3]);
                this.receiveMsg(msg);
            }
            catch (e:Error)
            {
                throw new Error("聊天数据错误");
            }
            return;
        }// end function

        public function receiveWDAnnounce(param1:Array, param2:int = -1) : void
        {
            var _loc_3:ChatVO = null;
            try
            {
                _loc_3 = new ChatVO();
                if (param2 == -1)
                {
                    _loc_3.Type = ChatCMD.ChannelSystem;
                }
                else if (param2 == 1)
                {
                    _loc_3.Type = ChatCMD.ChannelUnion;
                    _loc_3.RoleName = "行会情报员";
                }
                _loc_3.TalkContent = ChatWDContent.getContent(param1);
                if (_loc_3.TalkContent == null)
                {
                    return;
                }
                this.receiveMsg(_loc_3);
            }
            catch (e:Error)
            {
            }
            return;
        }// end function

        public function receiveString(param1:String, param2:int, param3:int = 0) : void
        {
            var _loc_4:* = param1.split(this.SEPARATE);
            var _loc_5:* = new ChatVO();
            new ChatVO().Type = param2;
            _loc_5.RoleID = _loc_4[0];
            _loc_5.RoleName = _loc_4[1];
            _loc_5.RoleVip = _loc_4[2];
            _loc_5.ToRoleID = _loc_4[3];
            _loc_5.ToRoleName = _loc_4[4];
            _loc_5.TeamID = _loc_4[5];
            _loc_5.UnionID = _loc_4[6];
            _loc_5.TalkContent = String(_loc_4[7]);
            if (param2 == ChatCMD.ChannelPrivate)
            {
                _loc_5.sex = _loc_4[8];
                _loc_5.career = _loc_4[9];
                _loc_5.rein = _loc_4[10];
                _loc_5.level = _loc_4[11];
                _loc_5.title = _loc_4[12];
                _loc_5.itemList = _loc_4[13];
                _loc_5.msgToAnnounce = _loc_4[14];
                if (_loc_4[15])
                {
                    _loc_5.isGm = _loc_4[15];
                }
            }
            else if (param2 == ChatCMD.ChannelUnion)
            {
                _loc_5.sex = _loc_4[8];
                _loc_5.career = _loc_4[9];
                _loc_5.title = _loc_4[10];
                _loc_5.itemList = _loc_4[11];
                _loc_5.msgToAnnounce = _loc_4[12];
                if (_loc_4[13])
                {
                    _loc_5.isGm = _loc_4[13];
                }
            }
            else
            {
                _loc_5.title = _loc_4[8];
                _loc_5.itemList = _loc_4[9];
                _loc_5.msgToAnnounce = _loc_4[10];
                if (_loc_4[11])
                {
                    _loc_5.isGm = _loc_4[11];
                }
            }
            if (_loc_5.RoleName.length > 13)
            {
                return;
            }
            if (_loc_5.Type == ChatCMD.ChannelSystem)
            {
                return;
            }
            if (_loc_5.Type == ChatCMD.ChannelStage)
            {
                ModelProxy.change("zone", "roleTalk", {rid:_loc_5.RoleID, name:_loc_5.RoleName, msg:_loc_5.TalkContent, serverid:param3});
            }
            this.receiveMsg(_loc_5);
            return;
        }// end function

        public function receiveMsg(param1:ChatVO) : void
        {
            var _loc_5:Array = null;
            var _loc_6:int = 0;
            var _loc_7:int = 0;
            var _loc_8:Array = null;
            var _loc_9:Object = null;
            var _loc_10:Array = null;
            var _loc_11:String = null;
            var _loc_12:Object = null;
            var _loc_13:Array = null;
            var _loc_14:int = 0;
            var _loc_15:int = 0;
            var _loc_16:int = 0;
            var _loc_17:Object = null;
            var _loc_18:String = null;
            var _loc_19:ChatChannelBase = null;
            if (param1.RoleID > 0)
            {
                _loc_5 = ModelProxy.getValue("data", "heilist");
                if (_loc_5 && _loc_5.length > 0)
                {
                    _loc_6 = 0;
                    _loc_7 = _loc_5.length;
                    _loc_6 = 0;
                    while (_loc_6 < _loc_7)
                    {
                        
                        if (param1.RoleID == _loc_5[_loc_6])
                        {
                            return;
                        }
                        _loc_6++;
                    }
                }
            }
            if (param1.msgToAnnounce)
            {
                _loc_8 = param1.msgToAnnounce.split(",");
                _loc_9 = ConfigDictionary.data.announce[_loc_8[0]];
                if (_loc_9 == null)
                {
                    return;
                }
                _loc_11 = "";
                if (_loc_8[0] == 319)
                {
                    _loc_12 = ConfigDictionary.data.maplist[_loc_8[3]];
                    if (_loc_12 == null)
                    {
                        return;
                    }
                    _loc_10 = [_loc_12.name, _loc_8[1], _loc_8[2], _loc_8[3]];
                    _loc_11 = StringUtil.substitute(_loc_9.text.replace(/\|""\|/gi, ","), _loc_10);
                }
                else if (_loc_8[0] == 320)
                {
                    _loc_12 = ConfigDictionary.data.maplist[_loc_8[3]];
                    if (_loc_12 == null)
                    {
                        return;
                    }
                    _loc_10 = [param1.RoleName, _loc_12.name, _loc_8[1], _loc_8[2], _loc_8[3]];
                    _loc_11 = StringUtil.substitute(_loc_9.text.replace(/\|""\|/gi, ","), _loc_10);
                }
                param1.TalkContent = _loc_11;
            }
            param1.tempContent = param1.TalkContent;
            var _loc_2:* = ConfigDictionary.data.item;
            if (param1.itemList)
            {
                _loc_13 = param1.itemList.split(",");
                _loc_13.pop();
                while (_loc_13.length > 0)
                {
                    
                    _loc_14 = _loc_13.shift();
                    _loc_15 = _loc_13.shift();
                    _loc_16 = _loc_13.shift();
                    _loc_17 = _loc_2[_loc_15];
                    if (_loc_17 != null)
                    {
                        if (_loc_14 == 1)
                        {
                            _loc_18 = "<font color=\'" + MColor.getqualitycolor(_loc_17.quality) + "\'><u>[<a href=\'event:item," + _loc_14 + "," + _loc_16 + "\'>" + _loc_17.name + "</a>]</u></font>";
                        }
                        else
                        {
                            _loc_18 = "<font color=\'" + MColor.getqualitycolor(_loc_17.quality) + "\'><u>[<a href=\'event:item," + _loc_14 + "," + _loc_15 + "\'>" + _loc_17.name + "</a>]</u></font>";
                        }
                        param1.TalkContent = param1.TalkContent.replace("[" + _loc_17.name + "]", _loc_18);
                    }
                }
            }
            param1.TalkContent = this.organizeMsg(param1);
            var _loc_3:* = this.getChannelByID(param1.Type);
            if (_loc_3)
            {
                _loc_3.receiveMsg(param1);
            }
            var _loc_4:* = this.getChannelByID(ChatCMD.ChannelAll);
            this.getChannelByID(ChatCMD.ChannelAll).receiveMsg(param1);
            if (param1.Type == ChatCMD.ChannelSpecial)
            {
                _loc_19 = this.getChannelByID(ChatCMD.ChannelWorld);
                _loc_19.receiveMsg(param1);
                ModelProxy.change("mainui", "showHorn", param1);
            }
            if (this.mChatUI.curChannelID == param1.Type || this.mChatUI.curChannelID == ChatCMD.ChannelWorld && param1.Type == ChatCMD.ChannelSpecial || this.mChatUI.curChannelID == 0)
            {
                this.deleteMsg();
                this.showMsg(param1);
                this.mChatUI.panel_chat.scrollTo(0, this.mChatUI.panel_chat.vScrollBar.max);
            }
            return;
        }// end function

        public function display() : void
        {
            this.clearAllMsg();
            this.mChatUI.panel_chat.changeScroll();
            var curChannel:* = this.getChannelByID(this.mChatUI.curChannelID);
            var len:* = curChannel.msgList.length;
            var i:int;
            i;
            while (i < len)
            {
                
                this.showMsg(curChannel.msgList[i]);
                i = (i + 1);
            }
            var func:* = function () : void
            {
                mChatUI.panel_chat.scrollTo(0, mChatUI.panel_chat.vScrollBar.max);
                return;
            }// end function
            ;
            setTimeout(func, 1000 / 24);
            return;
        }// end function

        private function showMsg(param1:ChatVO) : void
        {
            var _loc_8:Object = null;
            var _loc_9:RichTextField = null;
            var _loc_2:* = new RichTextField();
            _loc_2.textfield.mouseWheelEnabled = false;
            _loc_2.setSize(290, 100);
            _loc_2.type = RichTextField.DYNAMIC;
            _loc_2.html = true;
            var _loc_3:* = new TextFormat();
            _loc_3.leading = 5;
            _loc_2.textfield.defaultTextFormat = _loc_3;
            _loc_2.textfield.selectable = false;
            _loc_2.mouseChildren = true;
            _loc_2.textfield.filters = [this.mChatUI.mFilter];
            _loc_2.textfield.addEventListener(FocusEvent.FOCUS_IN, this.cancelFocusHandler);
            _loc_2.textfield.addEventListener(TextEvent.LINK, this.linkHandler);
            _loc_2.textfield.addEventListener(MouseEvent.MOUSE_DOWN, this.stop);
            var _loc_4:Array = [];
            var _loc_5:String = "";
            if (param1.RoleVip > 0)
            {
                _loc_5 = "[VIP]";
            }
            if (param1.Type == 6)
            {
                if (param1.RoleID == UserData.getUserData("rid"))
                {
                    this.checkSprites("【" + UIGlobel.chanelToname(param1.Type) + "】" + param1.titleMsg + "你对" + param1.ToRoleName + "说:" + param1.tempContent, _loc_4);
                }
                else
                {
                    this.checkSprites("【" + UIGlobel.chanelToname(param1.Type) + "】" + param1.titleMsg + param1.RoleName + _loc_5 + "对你说:" + param1.tempContent, _loc_4);
                }
            }
            else
            {
                this.checkSprites("【" + UIGlobel.chanelToname(param1.Type) + "】" + param1.titleMsg + param1.RoleName + _loc_5 + ":" + param1.tempContent, _loc_4);
            }
            _loc_2.append(this.getMsg(param1.TalkContent), _loc_4, false, null, false);
            _loc_2.setSize(290, _loc_2.height);
            _loc_2.x = 17;
            var _loc_6:Boolean = true;
            switch(_loc_2.height)
            {
                case 24:
                {
                    _loc_2.showHeight = 20;
                    _loc_6 = false;
                    break;
                }
                case 39:
                {
                    _loc_2.showHeight = 40;
                    break;
                }
                case 59:
                {
                    _loc_2.showHeight = 60;
                    break;
                }
                case 79:
                {
                    _loc_2.showHeight = 80;
                    break;
                }
                case 99:
                {
                    _loc_2.showHeight = 100;
                    break;
                }
                default:
                {
                    _loc_2.showHeight = _loc_2.height;
                    break;
                    break;
                }
            }
            this.mChatUI.panel_chat.addChild(_loc_2);
            this.mTextList.push({value:_loc_2, key:this.faceKey});
            if (this.whiteSpace)
            {
                if (this.whiteSpace.parent)
                {
                    this.mChatUI.panel_chat.removeChild(this.whiteSpace);
                }
            }
            var _loc_7:int = 0;
            for each (_loc_8 in this.mTextList)
            {
                
                _loc_9 = _loc_8.value as RichTextField;
                _loc_9.y = _loc_7;
                _loc_7 = _loc_7 + _loc_9.showHeight;
            }
            if (_loc_6)
            {
                this.mChatUI.panel_chat.addChild(this.whiteSpace);
                this.whiteSpace.y = _loc_7;
                _loc_7 = _loc_7 + 4;
            }
            this.mChatUI.panel_chat.scrollTo(0, _loc_7);
            var _loc_10:String = this;
            var _loc_11:* = this.faceKey + 1;
            _loc_10.faceKey = _loc_11;
            return;
        }// end function

        protected function stop(event:MouseEvent) : void
        {
            event.stopPropagation();
            return;
        }// end function

        private function checkSprites(param1:String, param2:Array) : void
        {
            var _loc_13:String = null;
            var _loc_14:int = 0;
            var _loc_15:Object = null;
            var _loc_16:Clip = null;
            var _loc_17:int = 0;
            var _loc_18:Object = null;
            var _loc_19:Clip = null;
            var _loc_3:* = ModelProxy.getValue("data", "chatTrie");
            var _loc_4:* = param1.length;
            var _loc_5:String = "";
            var _loc_6:* = _loc_3.getRoot();
            var _loc_7:* = ConfigDictionary.data.face;
            var _loc_8:int = 0;
            var _loc_9:Boolean = false;
            var _loc_10:Boolean = false;
            var _loc_11:Boolean = true;
            var _loc_12:int = 0;
            while (_loc_12 < _loc_4)
            {
                
                _loc_13 = param1.charAt(_loc_12);
                if (this.isChecking)
                {
                    if (_loc_6[_loc_13])
                    {
                        _loc_6 = _loc_6[_loc_13];
                        _loc_5 = _loc_5 + _loc_13;
                        if (_loc_12 == (_loc_4 - 1))
                        {
                            if (_loc_6[""])
                            {
                                this.isChecking = false;
                                _loc_9 = false;
                                _loc_10 = false;
                                _loc_11 = false;
                                _loc_6 = _loc_3.getRoot();
                                _loc_8++;
                                _loc_14 = 0;
                                for each (_loc_15 in _loc_7)
                                {
                                    
                                    if (_loc_15.protocol == _loc_5)
                                    {
                                        _loc_14 = _loc_15.times;
                                        break;
                                    }
                                }
                                _loc_16 = new Clip("png.common." + _loc_5.substr(1), _loc_14, 1);
                                if (this.faceDic[this.faceKey])
                                {
                                    this.faceDic[this.faceKey].push(_loc_16);
                                }
                                else
                                {
                                    this.faceDic[this.faceKey] = [_loc_16];
                                }
                                _loc_16.autoPlay = true;
                                _loc_16.interval = 900 / _loc_14 + 60;
                                param2.push({index:_loc_8, src:_loc_16});
                                _loc_5 = "";
                            }
                        }
                    }
                    else if (_loc_6[""])
                    {
                        _loc_6 = _loc_3.getRoot();
                        _loc_17 = 0;
                        for each (_loc_18 in _loc_7)
                        {
                            
                            if (_loc_18.protocol == _loc_5)
                            {
                                _loc_17 = _loc_18.times;
                                break;
                            }
                        }
                        _loc_19 = new Clip("png.common." + _loc_5.substr(1), _loc_17, 1);
                        if (this.faceDic[this.faceKey])
                        {
                            this.faceDic[this.faceKey].push(_loc_19);
                        }
                        else
                        {
                            this.faceDic[this.faceKey] = [_loc_19];
                        }
                        _loc_19.autoPlay = true;
                        _loc_19.interval = 900 / _loc_17 + 60;
                        _loc_5 = "";
                        if (_loc_6[_loc_13])
                        {
                            if (!_loc_9)
                            {
                                if (!_loc_10)
                                {
                                    if (!_loc_11)
                                    {
                                        _loc_8++;
                                    }
                                }
                            }
                            this.isChecking = true;
                            _loc_9 = true;
                            _loc_10 = false;
                            _loc_11 = false;
                            _loc_6 = _loc_6[_loc_13];
                            _loc_5 = _loc_5 + _loc_13;
                            param2.push({index:_loc_8, src:_loc_19});
                        }
                        else
                        {
                            param2.push({index:_loc_8, src:_loc_19});
                            this.isChecking = false;
                            _loc_11 = false;
                            _loc_8++;
                            _loc_10 = true;
                            _loc_9 = false;
                        }
                    }
                    else
                    {
                        _loc_6 = _loc_3.getRoot();
                        if (_loc_6[_loc_13])
                        {
                            this.isChecking = true;
                            _loc_6 = _loc_6[_loc_13];
                            _loc_8 = _loc_8 + _loc_5.length;
                            _loc_5 = "";
                            _loc_5 = _loc_5 + _loc_13;
                        }
                        else
                        {
                            this.isChecking = false;
                            _loc_9 = false;
                            _loc_5 = _loc_5 + _loc_13;
                            _loc_8 = _loc_8 + _loc_5.length;
                            _loc_5 = "";
                        }
                    }
                }
                else if (_loc_6[_loc_13])
                {
                    this.isChecking = true;
                    _loc_6 = _loc_6[_loc_13];
                    _loc_5 = _loc_5 + _loc_13;
                }
                else
                {
                    _loc_8++;
                }
                _loc_12++;
            }
            return;
        }// end function

        private function getMsg(param1:String) : String
        {
            var _loc_8:String = null;
            var _loc_2:* = ModelProxy.getValue("data", "chatTrie");
            var _loc_3:* = param1.length;
            var _loc_4:String = "";
            var _loc_5:String = "";
            var _loc_6:* = _loc_2.getRoot();
            var _loc_7:int = 0;
            while (_loc_7 < _loc_3)
            {
                
                _loc_8 = param1.charAt(_loc_7);
                if (this.isChecking)
                {
                    if (_loc_6[_loc_8])
                    {
                        _loc_6 = _loc_6[_loc_8];
                        _loc_5 = _loc_5 + _loc_8;
                    }
                    else if (_loc_6[""])
                    {
                        _loc_6 = _loc_2.getRoot();
                        _loc_5 = "";
                        if (_loc_6[_loc_8])
                        {
                            this.isChecking = true;
                            _loc_6 = _loc_6[_loc_8];
                            _loc_5 = _loc_5 + _loc_8;
                        }
                        else
                        {
                            this.isChecking = false;
                            _loc_4 = _loc_4 + _loc_8;
                        }
                    }
                    else
                    {
                        _loc_6 = _loc_2.getRoot();
                        if (_loc_6[_loc_8])
                        {
                            this.isChecking = true;
                            _loc_6 = _loc_6[_loc_8];
                            _loc_4 = _loc_4 + _loc_5;
                            _loc_5 = "";
                            _loc_5 = _loc_5 + _loc_8;
                        }
                        else
                        {
                            this.isChecking = false;
                            _loc_5 = _loc_5 + _loc_8;
                            _loc_4 = _loc_4 + _loc_5;
                            _loc_5 = "";
                        }
                    }
                }
                else if (_loc_6[_loc_8])
                {
                    this.isChecking = true;
                    _loc_6 = _loc_6[_loc_8];
                    _loc_5 = _loc_5 + _loc_8;
                }
                else
                {
                    _loc_4 = _loc_4 + _loc_8;
                }
                _loc_7++;
            }
            return _loc_4;
        }// end function

        private function deleteMsg() : void
        {
            var _loc_2:Object = null;
            var _loc_3:RichTextField = null;
            var _loc_4:Array = null;
            var _loc_5:Object = null;
            var _loc_1:* = this.getChannelByID(this.mChatUI.curChannelID);
            if (_loc_1)
            {
                while (this.mTextList.length > _loc_1.mMaxCount)
                {
                    
                    _loc_2 = this.mTextList.shift();
                    _loc_3 = _loc_2.value as RichTextField;
                    _loc_4 = this.faceDic[_loc_2.key];
                    if (_loc_4)
                    {
                        while (_loc_4.length > 0)
                        {
                            
                            _loc_5 = _loc_4.shift();
                            if (_loc_5 is Bitmap)
                            {
                                _loc_5.bitmapData.dispose();
                            }
                            if (_loc_5.parent)
                            {
                                _loc_5.parent.removeChild(_loc_5);
                            }
                            _loc_5 = null;
                        }
                    }
                    _loc_4 = null;
                    if (_loc_3.parent)
                    {
                        _loc_3.parent.removeChild(_loc_3);
                    }
                    _loc_3.textfield.removeEventListener(TextEvent.LINK, this.linkHandler);
                    _loc_3.textfield.removeEventListener(FocusEvent.FOCUS_IN, this.cancelFocusHandler);
                    _loc_3.textfield.removeEventListener(MouseEvent.MOUSE_DOWN, this.stop);
                    _loc_3.dispose();
                    _loc_3 = null;
                    _loc_2 = null;
                }
                this.mChatUI.panel_chat.changeScroll();
            }
            return;
        }// end function

        private function clearAllMsg() : void
        {
            var _loc_1:Object = null;
            var _loc_2:RichTextField = null;
            var _loc_3:Array = null;
            var _loc_4:Object = null;
            while (this.mTextList.length > 0)
            {
                
                _loc_1 = this.mTextList.shift();
                _loc_2 = _loc_1.value as RichTextField;
                _loc_3 = this.faceDic[_loc_1.key];
                if (_loc_3)
                {
                    while (_loc_3.length > 0)
                    {
                        
                        _loc_4 = _loc_3.shift();
                        if (_loc_4 is Bitmap)
                        {
                            _loc_4.bitmapData.dispose();
                        }
                        if (_loc_4.parent)
                        {
                            _loc_4.parent.removeChild(_loc_4);
                        }
                        _loc_4 = null;
                    }
                }
                _loc_3 = null;
                if (_loc_2.parent)
                {
                    _loc_2.parent.removeChild(_loc_2);
                }
                _loc_2.textfield.removeEventListener(TextEvent.LINK, this.linkHandler);
                _loc_2.textfield.removeEventListener(FocusEvent.FOCUS_IN, this.cancelFocusHandler);
                _loc_2.textfield.removeEventListener(MouseEvent.MOUSE_DOWN, this.stop);
                _loc_2.dispose();
                _loc_2 = null;
            }
            return;
        }// end function

        private function cancelFocusHandler(event:FocusEvent) : void
        {
            if (GlobalLayer.instance.root.focus == event.currentTarget)
            {
                GlobalLayer.instance.root.focus = null;
            }
            return;
        }// end function

        private function organizeMsg(param1:ChatVO) : String
        {
            return StringUtil.substitute("<font color=\'{2}\'>【{0}】</font>{1}<font color=\'{2}\'>{3}{4}</font>", UIGlobel.chanelToname(param1.Type), this.getTitle(param1), param1.isGm == "gm" ? (UIGlobel.chanel2color2(8)) : (UIGlobel.chanel2color2(param1.Type)), this.getLinkTalker(param1), param1.TalkContent);
        }// end function

        private function getTitle(param1:ChatVO) : String
        {
            var _loc_3:Object = null;
            var _loc_4:Object = null;
            var _loc_5:Object = null;
            var _loc_6:Object = null;
            var _loc_7:Object = null;
            var _loc_2:String = "";
            if (param1.isGm == "gm")
            {
                param1.titleMsg = "【GM】";
                return "<font color=\'#dec026\'><b>【GM】</b></font>";
            }
            if (param1.Type == ChatCMD.ChannelUnion)
            {
                _loc_3 = ModelProxy.getValue("union", "unioninfo");
                if (_loc_3)
                {
                    _loc_4 = _loc_3.members.source;
                    for each (_loc_5 in _loc_4)
                    {
                        
                        if (_loc_5.rid == param1.RoleID)
                        {
                            if (_loc_5.posname != "会员")
                            {
                                _loc_2 = "<font color=\'{0}\'>{1}</font>";
                                _loc_2 = StringUtil.substitute(_loc_2, "#4fa7db", "【" + _loc_5.posname + "】");
                                param1.titleMsg = "【" + _loc_5.posname + "】";
                                return _loc_2;
                            }
                            break;
                        }
                    }
                }
            }
            if (param1.title >= 1000)
            {
                _loc_2 = "<font color=\'{0}\'>{1}</font>";
                _loc_6 = ConfigDictionary.data.title;
                _loc_7 = _loc_6[param1.title];
                switch(int(_loc_7.type))
                {
                    case 0:
                    {
                        _loc_2 = StringUtil.substitute(_loc_2, "#cf6cec", "【" + _loc_7.name + "】");
                        param1.titleMsg = "【" + _loc_7.name + "】";
                        break;
                    }
                    case 1:
                    {
                        _loc_2 = StringUtil.substitute(_loc_2, "#d8a25c", "【" + _loc_7.name + "】");
                        param1.titleMsg = "【" + _loc_7.name + "】";
                        break;
                    }
                    default:
                    {
                        _loc_2 = StringUtil.substitute(_loc_2, "#cf6cec", "【" + _loc_7.name + "】");
                        param1.titleMsg = "【" + _loc_7.name + "】";
                        break;
                        break;
                    }
                }
            }
            return _loc_2;
        }// end function

        private function getLinkTalker(param1:ChatVO) : String
        {
            var _loc_4:String = null;
            var _loc_2:String = "";
            var _loc_3:String = "";
            if (param1.RoleVip > 0)
            {
                _loc_3 = "<font color=\'#e19f21\'>[VIP]</font>";
            }
            if (param1.Type == ChatCMD.ChannelPrivate)
            {
                if (param1.RoleID == UserData.getUserData("rid"))
                {
                    _loc_2 = "你对<font color=\'#fbaaf9\'><u><a href=\'event:user,{0},{1}\'>{1}</a></u></font>说：";
                    _loc_2 = StringUtil.substitute(_loc_2, param1.ToRoleID, param1.ToRoleName);
                }
                else
                {
                    _loc_2 = "<font color=\'#fbaaf9\'><u><a href=\'event:user,{0},{1}\'>{1}</a></u>" + _loc_3 + "</font>对你说：";
                    _loc_2 = StringUtil.substitute(_loc_2, param1.RoleID, param1.RoleName);
                }
            }
            else if (param1.RoleID == UserData.getUserData("rid"))
            {
                _loc_2 = StringUtil.substitute("<font color=\'{0}\'>{1}" + _loc_3 + "</font>：", "#fedb9b", param1.RoleName);
            }
            else if (param1.RoleID > 0)
            {
                _loc_4 = "#fedb9b";
                _loc_2 = "<font color=\'{0}\'><u><a href=\'event:user,{1},{2}\'>{2}</a></u>" + _loc_3 + "</font>：";
                _loc_2 = StringUtil.substitute(_loc_2, _loc_4, param1.RoleID, param1.RoleName);
            }
            return _loc_2;
        }// end function

        private function linkHandler(event:TextEvent) : void
        {
            var links:Array;
            var p:Point;
            var fun:Function;
            var openLevels:Object;
            var lv:int;
            var rein:int;
            var data:Object;
            var rid:int;
            var itemInfo:Object;
            var skillInfo:Object;
            var fun1:Function;
            var limit:Object;
            var user:Object;
            var event:* = event;
            event.stopImmediatePropagation();
            links = event.text.split(",");
            if (links.length > 0)
            {
                p = new Point(GlobalLayer.instance.root.mouseX, GlobalLayer.instance.root.mouseY);
                switch(links[0])
                {
                    case "user":
                    {
                        if (links[1] != UserData.getUserData("rid"))
                        {
                            this.mChatUI.mMenu.show(p.x, p.y, {rid:links[1], name:links[2]});
                        }
                        break;
                    }
                    case "jsfunc":
                    {
                        ExternalInterface.call(links[1]);
                        break;
                    }
                    case "item":
                    {
                        if (this.mShowingTip)
                        {
                            this.mShowingTip = false;
                            GlobalLayer.instance.root.removeEventListener(MouseEvent.CLICK, this.checkCloseTipHandler);
                            ModelProxy.change("tips", "state", "close");
                        }
                        if (links[1] == 2)
                        {
                            p.y = p.y - 200;
                            itemInfo = ConfigDictionary.data.item[links[2]];
                            if (itemInfo.itemtype == 1)
                            {
                                ModelProxy.change("tips", "arm", {data:itemInfo, p:p});
                            }
                            else
                            {
                                ModelProxy.change("tips", "tool", {data:itemInfo, p:p});
                            }
                        }
                        else
                        {
                            Server.instance.send(110, 9, links[2], 0, ConnectType.SYSTEM);
                        }
                        this.mShowingTip = true;
                        fun = function () : void
            {
                GlobalLayer.instance.root.addEventListener(MouseEvent.CLICK, checkCloseTipHandler);
                return;
            }// end function
            ;
                        setTimeout(fun, 100);
                        break;
                    }
                    case "skill":
                    {
                        if (this.mShowingTip)
                        {
                            this.mShowingTip = false;
                            GlobalLayer.instance.root.removeEventListener(MouseEvent.CLICK, this.checkCloseTipHandler);
                            ModelProxy.change("tips", "state", "close");
                        }
                        if (links[1] == 2)
                        {
                            skillInfo = ConfigDictionary.data.skill[links[2]];
                            if (skillInfo)
                            {
                                ModelProxy.change("tips", "skill", {data:skillInfo, p:p});
                            }
                            this.mShowingTip = true;
                            fun1 = function () : void
            {
                GlobalLayer.instance.root.addEventListener(MouseEvent.CLICK, checkCloseTipHandler);
                return;
            }// end function
            ;
                            setTimeout(fun1, 100);
                        }
                        break;
                    }
                    case "pos":
                    {
                        if (links[3] < 10000)
                        {
                            ModelProxy.change("zone", "autoMove", {x:links[1], y:links[2], tostageid:links[3], onhorse:true});
                        }
                        else
                        {
                            ModelProxy.change("movetips", "error", "目标为不可寻路到达的目的地，不能前往！");
                        }
                        break;
                    }
                    case "transfer":
                    {
                        if (links[4])
                        {
                            ModelProxy.change("data", "taskfindpath", links[4]);
                        }
                        PluginManager.instance.sendToServer("activity", CMDActivity.Trans, {x:links[1], y:links[2], tostageid:links[3], free:1});
                        break;
                    }
                    case "stallage":
                    {
                        ModelProxy.change("plugin", "sendSysMsg", {name:"stallage", param:links[1], cmd:8});
                        break;
                    }
                    case "recharge":
                    {
                        if (Config.gameParams.oper == "qq")
                        {
                            ModelProxy.change("plugin", "open", {target:"qqchongzhi"});
                        }
                        else
                        {
                            if (!ItemUilt.canpay)
                            {
                                ModelProxy.change("movetips", "error", "功能尚未开放，敬请期待");
                                return;
                            }
                            ExternalInterface.call("topay");
                        }
                        break;
                    }
                    case "plugin":
                    {
                        openLevels = ConfigDictionary.data.openlevel;
                        lv = UserData.getUserData("level");
                        rein = ModelProxy.getValue("data", "user.rein");
                        if (openLevels[links[1]])
                        {
                            if (links[2])
                            {
                                limit = openLevels[links[1]][links[2]];
                                if (limit)
                                {
                                    if (rein < limit.rein)
                                    {
                                        WarningManager.show(30, ["转生等级" + limit.rein, "该功能"]);
                                    }
                                    else if (lv < limit.level)
                                    {
                                        WarningManager.show(30, [limit.level, "该功能"]);
                                    }
                                }
                            }
                        }
                        if (links[1] == "tracing")
                        {
                            data;
                        }
                        else
                        {
                            data = links[2];
                        }
                        ModelProxy.change("plugin", "change", {target:links[1], point:p, data:data});
                        break;
                    }
                    case "multiinstance":
                    {
                        if (ModelProxy.getValue("data", "hasMultiGroup"))
                        {
                            ModelProxy.change("movetips", "error", "您已有队伍");
                        }
                        else
                        {
                            user = UserData.getUserData();
                            if (user.mapid > 10000)
                            {
                                ModelProxy.change("movetips", "error", "您已在副本中，不能进入该副本队列中！");
                            }
                            else
                            {
                                ModelProxy.change("data", "isMultiInstanceJoinning", true);
                            }
                        }
                        break;
                    }
                    case "jiebiao":
                    {
                        rid = links[1];
                        Alert2.show("本次传送需要消耗10000金币，确定传送至该镖车处吗？", "", ["确定", "取消"], function (param1:int, param2:Object = null) : void
            {
                if (param1 == 0)
                {
                }
                return;
            }// end function
            , null, false, true, false);
                        break;
                    }
                    case "unionEmsTrans":
                    {
                        UnionSender._62unionEmsJoin();
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
            }
            return;
        }// end function

        private function checkCloseTipHandler(event:MouseEvent) : void
        {
            if (this.mShowingTip)
            {
                this.mShowingTip = false;
                GlobalLayer.instance.root.removeEventListener(MouseEvent.CLICK, this.checkCloseTipHandler);
                ModelProxy.change("tips", "state", "close");
            }
            return;
        }// end function

        private function getChannelByID(param1:int) : ChatChannelBase
        {
            var _loc_2:* = this.mChannels.length;
            var _loc_3:int = 0;
            while (_loc_3 < _loc_2)
            {
                
                if (this.mChannels[_loc_3].channelID == param1)
                {
                    return this.mChannels[_loc_3];
                }
                _loc_3++;
            }
            return null;
        }// end function

    }
}
